<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
%>
<html>
    <head>
        <title>Scriptler Web - scripts for hudson</title>
        
        <link rel="shortcut icon" href="/images/gaelyk-small-favicon.png" type="image/png">
        <link rel="icon" href="/images/gaelyk-small-favicon.png" type="image/png">
	
		<!-- Simple OpenID Selector -->
		<link rel="stylesheet" type="text/css" href="/css/openid.css" />
        <link rel="stylesheet" type="text/css" href="/css/main.css"/>
        <script type="text/javascript" src="/js/jquery-1.2.6.min.js"></script>
        <script type="text/javascript">
		function rate(id,rating) {
			jQuery.ajax({
				   type: "POST",
				   url: "/script/rate/"+id+"/"+rating,
				   success: function(msg){
				     alert('Thanks!'); 
				     location.reload();
				   }
				 });
			}
		</script>
	<script type="text/javascript">
	jQuery(document).ready(function() {
	    openid.init('openid_identifier');
	});
	</script>
    </head>
    <%
	 Map<String, String> openIdProviders;
		openIdProviders = new HashMap<String, String>();
		openIdProviders.put("Google", "google.com/accounts/o8/id");
		openIdProviders.put("Yahoo", "yahoo.com");
		openIdProviders.put("MySpace", "myspace.com");
		openIdProviders.put("AOL", "aol.com");
		openIdProviders.put("MyOpenId.com", "myopenid.com");
		openIdProviders.put("meiner", "domi.fortysix.ch");
	
		def userSrv = UserServiceFactory.getUserService()
		
	User user1 = userSrv.getCurrentUser(); // XXX what about
												// req.getUserPrincipal()?!?
	
	
	Set<String> attributes = new HashSet();


	if (user1 != null) {
		out.println("Hello <i>" + user1.getNickname() + "</i>!");
		out.println("[<a href=\""
				+ userSrv.createLogoutURL(request.getRequestURI())
				+ "\">sign out</a>]");
	} else {
		out.println("Hello world! Sign in at: ");
		for (String providerName : openIdProviders.keySet()) {
			String providerUrl = openIdProviders.get(providerName);
			String loginUrl = users.createLoginURL(request
					.getRequestURI(), null, providerUrl, attributes);
			out.println("[<a href=\"" + loginUrl + "\">" + providerName
					+ "</a>] ");
		}
	}   
    %>
    <body>
        <div>
        	<span class="title">Scriptler</span>
        </div>
    <p>
currentUser: <% userSrv.getCurrentUser() %><br/>
loggedin?: <%= userSrv.isUserLoggedIn() %><br/>
admin?: <% if(userSrv.isUserLoggedIn()) { 
	out.write(""+userSrv.isUserAdmin())
	out.write("<br>getAuthDomain() : "+user1.getAuthDomain())
	out.write("<br>getEmail()"+user1.getEmail())
	out.write("<br>getFederatedIdentity()"+user1.getFederatedIdentity())
	out.write("<br>getUserId()"+user1.getUserId())
	
}%><br/>
user: <%= user1 %>
</p>
    	<div id="topNav">
    		<table>
    			<tr><td><a href="/catalog/list">catalog</a> | <a href="/catalog/xml">xml</a> | <a href="/provider/list">providers</a> | <a href="/sec/script/new">provide a new script</a> | <a href="/sec/provider/edit">edit your provider profile</a> | <a href="/about">about</a></td></tr>
 			</table>
		</div>
		
        <div id="msg">
        <% if (request.getAttribute('msg')) { %> 
			<b><%= request.getAttribute('msg') %></b>
		<% } %>
        </div>
        <div>
